package sunmi.payment.L3;

import android.graphics.Bitmap;
import android.os.RemoteException;

import mi.payment.constants.Params;
import mi.payment.utils.CodeUtil;
import woyou.aidlservice.jiuiv5.IWoyouService;

/**
 * @author Lee64 on 2017/7/12.
 */

public class L3PrintUtil {

    public static void l3UserAddPrinter(IWoyouService printerService) throws RemoteException {
        L3Params l3Params = Params.sL3Params;
        if (l3Params == null) return;
        boolean isPrint = false;
        // 用户联追加打印
        String printInfo = l3Params.printInfo;
        if (printInfo != null && printInfo.length() > 0) {
            isPrint = true;
            printerService.sendRAWData(new byte[]{0x1B, 0x33, 0x10}, null);
            printerService.printTextWithFont("\n\n" + printInfo, "", 18, null);
            printerService.setAlignment(0, null);
        }
        // 用户联追加二维码
        String printInfo2 = l3Params.printInfo2;
        if (printInfo2 != null && printInfo2.length() > 0) {
            isPrint = true;
            printerService.sendRAWData(new byte[]{0x1B, 0x33, 0x10}, null);
            printerService.printTextWithFont("\n\n", "", 18, null);
            Bitmap bitmap = CodeUtil.createCodeBitmap(printInfo2, 210, 210);
            printerService.printBitmap(bitmap, null);
            printerService.setAlignment(1, null);
        }
        if (isPrint) {
            printerService.sendRAWData(new byte[]{0x1B, 0x33, 0x10}, null);
            printerService.printTextWithFont("\n\n", "", 18, null);
            printerService.setAlignment(0, null);
        }
    }

    public static void l3MerchantAddPrinter(IWoyouService printerService) throws RemoteException {
        L3Params l3Params = Params.sL3Params;
        if (l3Params == null) return;
        boolean isPrint = false;
        // 商户联追加打印
        String printMerchantInfo = l3Params.printMerchantInfo;
        if (printMerchantInfo != null && printMerchantInfo.length() > 0) {
            isPrint = true;
            printerService.sendRAWData(new byte[]{0x1B, 0x33, 0x10}, null);
            printerService.printTextWithFont("\n\n" + printMerchantInfo, "", 18, null);
            printerService.setAlignment(0, null);
        }
        // 商户联追加二维码
        String printMerchantInfo2 = l3Params.printMerchantInfo2;
        if (printMerchantInfo2 != null && printMerchantInfo2.length() > 0) {
            isPrint = true;
            printerService.sendRAWData(new byte[]{0x1B, 0x33, 0x10}, null);
            printerService.printTextWithFont("\n\n", "", 18, null);
            Bitmap bitmap = CodeUtil.createCodeBitmap(printMerchantInfo2, 210, 210);
            printerService.printBitmap(bitmap, null);
            printerService.setAlignment(1, null);
        }
        if (isPrint) {
            printerService.sendRAWData(new byte[]{0x1B, 0x33, 0x10}, null);
            printerService.printTextWithFont("\n\n", "", 18, null);
            printerService.setAlignment(0, null);
        }
    }


}
